import axios from "axios"
import { message } from 'antd'
import { meshLog } from "../config";
const instance = axios.create({
    timeout: 10000,
});
//请求拦截器
instance.interceptors.request.use((config) => {
    //输入函数体
    const { method, data } = config
    // meshLog(method)
    // meshLog(data)
    //若是post请求
    if (method.toLowerCase() === 'post') {
        //若传过来的参数是对象
        if (data instanceof Object) {
            config.data = data
            //meshLog('发送到服务器的数据', data);
            //meshLog('上传成功');
        }
    }
    return config;
});
//响应拦截器
instance.interceptors.response.use(
    (response) => {
        //请求成功，走这里。拿到修改之后的结果
        return response.data;
    },
    (error) => {
        //请求失败，走这里，提示网络错了
        // message.error(error.message, 1)
        message.info('The operation failed. Please check your network connection');
        meshLog("请求失误");
        return new Promise(() => { })
    }
);
export default instance
